package com.xhc.demo.repository;

import com.xhc.demo.entity.PhotoAccessLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime;

public interface PhotoAccessLogRepository extends JpaRepository<PhotoAccessLog, Long> {
    @Query("SELECT COUNT(p) FROM PhotoAccessLog p WHERE p.userId = :userId AND p.photoId = :photoId AND p.accessTime > :time")
    long countRecentAccesses(@Param("userId") Long userId, @Param("photoId") Long photoId, @Param("time") LocalDateTime time);

    @Query("SELECT COUNT(p) FROM PhotoAccessLog p WHERE p.ipAddress = :ipAddress AND p.accessTime > :time")
    long countRecentAccessesByIp(@Param("ipAddress") String ipAddress, @Param("time") LocalDateTime time);
}
